/**
 * Created by huanggw on 2015/11/7.
 */

var registApp = angular.module('regist',[]);
registApp.controller('regCtrl', function($scope, $timeout) {
    $scope.regStatus = 0;
    $scope.regForm = function() {
        var url = host+"/regist";
        var obj = {
            username: $scope.username,
            useremail: $scope.useremail,
            password: $scope.password
        }
        xhr.open("POST", url, true);
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

        xhr.onreadystatechange=function(){
            if(xhr.readyState==4){
                if(xhr.status==200){
                    $timeout(function(){
                        var result = JSON.parse(xhr.responseText)
                        var form = document.getElementById("form");
                        var success = document.getElementById("success");
                        form.style.opacity = 0;
                        success.style.display = 'block';
                        if(result.regStatus == 0) {
                            $scope.regTip = "注册失败，"+result.content;
                            $scope.regStatus = 0;
                        }
                        else {
                            $scope.regTip = "注册成功，您的用户名是"+result.content;
                            $scope.regStatus = 1;
                        }
                        $timeout(function(){
                            form.style.display = 'none'
                            $scope.status = "form-success"
                        }, 300);
                    },20)
                }
                else {

                }
            }
        }
        xhr.send(JSON.stringify(obj));
    }
})